chrome.runtime.sendMessage("requestConnection", function (res) {
    chrome.runtime.onMessage.addListener(function (tabs, sender, sendResponse) {
        let body = document.querySelector("#root")
        body.innerHTML = tabs.map((t) => `<div class='tab-item'>${t.title}</div>`).join("")
        var eles = document.getElementsByClassName("tab-item")

        document.getElementById("tab-header-btn").addEventListener("click", function () {

        })

        // 这里只能这种for 循环，增强的for循环有问题
        for (let index = 0; index < eles.length; index++) {
            const ele = eles[index];
            ele.addEventListener("click", function () {
                chrome.runtime.sendMessage({ id: tabs[index].id }, function (res) {
                    window.close()
                })
            })
        }
        sendResponse("done??")
    })
})

function clickTabItem(tabId) {
    console.log("click>>>" + tabId)
    // chrome.runtime.sendMessage({tabId:tabId},function(res){

    // })
    window.close()
}

// function click(e) {
//     chrome.tabs.executeScript(
//         { code: "document.body.style.backgroundColor='" + e.target.id + "'" });
//     window.close();
// }

// document.addEventListener('DOMContentLoaded', function () {
//     var divs = document.querySelectorAll('div');
//     for (var i = 0; i < divs.length; i++) {
//         divs[i].addEventListener('click', click);
//     }
// });